<html>
<head>
	<title>Wiki: Calculator Example</title>
<head>
<body bgcolor=#FFFFFF link=#d06040 vlink=#806040>
	<h1>Calculator Example</h1>
	
<wiki>
The HP-35 was HP's first pocket calculator. It was introduced at a time when most calculators had only the four basic functions. The HP-35 was the first pocket calculator with transcendental functions, and the first with RPN. 
<p>The following specifications have been derived from the instructions printed on the back of the calculator. (Image from <a href="//www.hpmuseum.org/hp35.htm">http://www.hpmuseum.org/hp35.htm</a>.)
<p><img src="files/hp35bk.jpg">
<p><p>Low battery lights all decimal points.
<p>
<table BORDER CELLSPACING=0 CELLPADDING=3>


<tr>

<td ColSpan=3>
    eg.Calculator
</td>

</tr>


<tr>

<td>
volts
</td>

<td>
watts()
</td>

<td>
points()
</td>

</tr>


<tr>

<td>
3.75
</td>

<td bgcolor="#cfffcf">
.500
</td>

<td bgcolor="#cfffcf">
false
</td>

</tr>


<tr>

<td>
3.60
</td>

<td bgcolor="#cfffcf">
.500
</td>

<td bgcolor="#cfffcf">
false
</td>

</tr>


<tr>

<td>
3.45
</td>

<td bgcolor="#cfffcf">
.500
</td>

<td bgcolor="#cfffcf">
false
</td>

</tr>


<tr>

<td>
3.30
</td>

<td bgcolor="#cfffcf">
.500
</td>

<td bgcolor="#ffcfcf">
true <font size=-1 color="#c08080"><i>expected</i></font><hr>false <font size=-1 color="#c08080"><i>actual</i></font>
</td>

</tr>


</table>

<p>Improper operations flash display. Press <strong>clx</strong>.
<p>
<table BORDER CELLSPACING=0 CELLPADDING=3>


<tr>

<td ColSpan=3>
    eg.Calculator
</td>

</tr>


<tr>

<td>
key
</td>

<td>
x()
</td>

<td>
flash()
</td>

</tr>


<tr>

<td>
100
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
false
</td>

</tr>


<tr>

<td>
enter
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
false
</td>

</tr>


<tr>

<td>
0
</td>

<td bgcolor="#cfffcf">
0
</td>

<td bgcolor="#cfffcf">
false
</td>

</tr>


<tr>

<td>
/
</td>

<td bgcolor="#ffcfcf">
0 <font size=-1 color="#c08080"><i>expected</i></font><hr>Infinity <font size=-1 color="#c08080"><i>actual</i></font>
</td>

<td bgcolor="#ffcfcf">
true <font size=-1 color="#c08080"><i>expected</i></font><hr>false <font size=-1 color="#c08080"><i>actual</i></font>
</td>

</tr>


<tr>

<td>
clx
</td>

<td bgcolor="#cfffcf">
0
</td>

<td bgcolor="#cfffcf">
false
</td>

</tr>


</table>

<p><strong>clx</strong> clears the display.
<p>
<table BORDER CELLSPACING=0 CELLPADDING=3>


<tr>

<td ColSpan=5>
    eg.Calculator
</td>

</tr>


<tr>

<td>
key
</td>

<td>
x()
</td>

<td>
y()
</td>

<td>
z()
</td>

<td>
t()
</td>

</tr>


<tr>

<td>
100
</td>

<td bgcolor="#cfffcf">
100
</td>

<td>
&nbsp; <font color="#808080">0</font>
</td>

<td>
&nbsp; <font color="#808080">100</font>
</td>

<td>
&nbsp; <font color="#808080">0</font>
</td>

</tr>


<tr>

<td>
enter
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
100
</td>

<td>
&nbsp; <font color="#808080">0</font>
</td>

<td>
&nbsp; <font color="#808080">100</font>
</td>

</tr>


<tr>

<td>
enter
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
100
</td>

<td>
&nbsp; <font color="#808080">0</font>
</td>

</tr>


<tr>

<td>
enter
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
100
</td>

</tr>


<tr>

<td>
clx
</td>

<td bgcolor="#cfffcf">
0
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
100
</td>

</tr>


</table>

<p><strong>clr</strong> clears all registers.
<p>
<table BORDER CELLSPACING=0 CELLPADDING=3>


<tr>

<td ColSpan=5>
    eg.Calculator
</td>

</tr>


<tr>

<td>
key
</td>

<td>
x()
</td>

<td>
y()
</td>

<td>
z()
</td>

<td>
t()
</td>

</tr>


<tr>

<td>
100
</td>

<td bgcolor="#cfffcf">
100
</td>

<td>
&nbsp; <font color="#808080">0</font>
</td>

<td>
&nbsp; <font color="#808080">100</font>
</td>

<td>
&nbsp; <font color="#808080">100</font>
</td>

</tr>


<tr>

<td>
enter
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
100
</td>

<td>
&nbsp; <font color="#808080">0</font>
</td>

<td>
&nbsp; <font color="#808080">100</font>
</td>

</tr>


<tr>

<td>
enter
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
100
</td>

<td>
&nbsp; <font color="#808080">0</font>
</td>

</tr>


<tr>

<td>
enter
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
100
</td>

</tr>


<tr>

<td>
clr
</td>

<td bgcolor="#cfffcf">
0
</td>

<td bgcolor="#cfffcf">
0
</td>

<td bgcolor="#cfffcf">
0
</td>

<td bgcolor="#cfffcf">
0
</td>

</tr>


</table>

<p><strong>chs</strong> changes sign of display. May be used as the first entry when entering negative numbers.
<p>
<table BORDER CELLSPACING=0 CELLPADDING=3>


<tr>

<td ColSpan=3>
    eg.Calculator
</td>

</tr>


<tr>

<td>
key
</td>

<td>
x()
</td>

<td>
y()
</td>

</tr>


<tr>

<td>
100
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
0
</td>

</tr>


<tr>

<td>
chs
</td>

<td bgcolor="#cfffcf">
-100
</td>

<td bgcolor="#cfffcf">
0
</td>

</tr>


<tr>

<td>
chs
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
0
</td>

</tr>


<tr>

<td>
enter
</td>

<td bgcolor="#cfffcf">
100
</td>

<td bgcolor="#cfffcf">
100
</td>

</tr>


<tr>

<td>
chs
</td>

<td bgcolor="#ffcfcf">
-0 <font size=-1 color="#c08080"><i>expected</i></font><hr>-100 <font size=-1 color="#c08080"><i>actual</i></font>
</td>

<td bgcolor="#cfffcf">
100
</td>

</tr>


<tr>

<td>
100
</td>

<td bgcolor="#ffcfcf">
-100 <font size=-1 color="#c08080"><i>expected</i></font><hr>100 <font size=-1 color="#c08080"><i>actual</i></font>
</td>

<td bgcolor="#ffcfcf">
100 <font size=-1 color="#c08080"><i>expected</i></font><hr>-100 <font size=-1 color="#c08080"><i>actual</i></font>
</td>

</tr>


</table>

<p><strong>eex</strong> causes next entries to become the exponent of x. For negative expoinents <strong>chs</strong> must precede digits.
<p>The operational stack consistes of four registers (x, y, z and t). A fifth register (s) is used for constant storage.
<p>The stack is automatically raised by an entry into x or by <strong>rcl</strong> unless the entry or <strong>rcl</strong> immediately follows <strong>clx</strong>, <strong>sto</strong> or <strong>enter</strong>.
<p>Follwing any trig function z is duplicated into register t.
<p>All angles are in degrees.
<p>Example (2+3) * (4/5) / sin(30) * (4^-1.5) = 1.0000
<p>
<table BORDER CELLSPACING=0 CELLPADDING=3>


<tr>

<td ColSpan=3>
    eg.Calculator
</td>

</tr>


<tr>

<td>
key
</td>

<td>
x()
</td>

<td>
y()
</td>

</tr>


<tr>

<td>
2
</td>

<td bgcolor="#cfffcf">
2
</td>

<td>
&nbsp; <font color="#808080">100</font>
</td>

</tr>


<tr>

<td>
enter
</td>

<td bgcolor="#cfffcf">
2
</td>

<td bgcolor="#cfffcf">
2
</td>

</tr>


<tr>

<td>
3
</td>

<td bgcolor="#cfffcf">
3
</td>

<td bgcolor="#cfffcf">
2
</td>

</tr>


<tr>

<td>
+
</td>

<td bgcolor="#cfffcf">
5
</td>

<td>
&nbsp; <font color="#808080">2</font>
</td>

</tr>


<tr>

<td>
4
</td>

<td bgcolor="#cfffcf">
4
</td>

<td bgcolor="#cfffcf">
5
</td>

</tr>


<tr>

<td>
*
</td>

<td bgcolor="#cfffcf">
20
</td>

<td>
&nbsp; <font color="#808080">2</font>
</td>

</tr>


<tr>

<td>
5
</td>

<td bgcolor="#cfffcf">
5
</td>

<td bgcolor="#cfffcf">
20
</td>

</tr>


<tr>

<td>
/
</td>

<td bgcolor="#cfffcf">
4
</td>

<td>
&nbsp; <font color="#808080">2</font>
</td>

</tr>


<tr>

<td>
30
</td>

<td bgcolor="#cfffcf">
30
</td>

<td bgcolor="#cfffcf">
4
</td>

</tr>


<tr>

<td>
sin
</td>

<td bgcolor="#cfffcf">
.5
</td>

<td bgcolor="#cfffcf">
4
</td>

</tr>


<tr>

<td>
/
</td>

<td bgcolor="#ffcfcf">
6 <font size=-1 color="#c08080"><i>expected</i></font><hr>8.000000000000002 <font size=-1 color="#c08080"><i>actual</i></font>
</td>

<td>
&nbsp; <font color="#808080">2</font>
</td>

</tr>


<tr>

<td>
-1.5
</td>

<td bgcolor="#cfffcf">
-1.5
</td>

<td bgcolor="#cfffcf">
8
</td>

</tr>


<tr>

<td>
enter
</td>

<td bgcolor="#cfffcf">
-1.5
</td>

<td bgcolor="#cfffcf">
-1.5
</td>

</tr>


<tr>

<td>
4
</td>

<td bgcolor="#cfffcf">
4
</td>

<td bgcolor="#cfffcf">
-1.5
</td>

</tr>


<tr>

<td>
x^y
</td>

<td bgcolor="#cfffcf">
.125
</td>

<td bgcolor="#ffcfcf">
8 <font size=-1 color="#c08080"><i>expected</i></font><hr>-1.5 <font size=-1 color="#c08080"><i>actual</i></font>
</td>

</tr>


<tr>

<td>
*
</td>

<td bgcolor="#ffcfcf">
1.0000 <font size=-1 color="#c08080"><i>expected</i></font><hr>-0.18750000000000006 <font size=-1 color="#c08080"><i>actual</i></font>
</td>

<td>
&nbsp; <font color="#808080">8.000000000000002</font>
</td>

</tr>


</table>

<p><hr>

<table BORDER CELLSPACING=0 CELLPADDING=3>


<tr>

<td>
eg.Summary
</td>

</tr>


<tr>


<td>
 <font color="#808080">counts</font>
</td>


<td bgcolor="#ffcfcf">
75 right, 9 wrong, 0 ignored, 0 exceptions
</td>

</tr>


<tr>


<td>
 <font color="#808080">run date</font>
</td>


<td>
 <font color="#808080">Thu Feb 21 15:02:00 GMT+0100 2008</font>
</td>

</tr>


<tr>


<td>
 <font color="#808080">run elapsed time</font>
</td>


<td>
 <font color="#808080">0:00.03</font>
</td>

</tr>

</table>

<hr>
<p>You can run this document as it stands right now against a calculator implemented at c2.com using the RunScript below. You will find that that the tests, the fixture and the calculator code are all not yet complete. Failing tests turn a cell red. There are two values in the cell. The top one is the expected result. The bottom is the actual result. 
<p><UL>
<li> <a href="run.cgi">http:run.cgi</a> -- invoke on c2.com and view results here
<li> <a href="hp35.cgi">http:hp35.cgi</a> -- model constrained generated test data
<li> <a href="Release/Source/eg/Calculator.java">http:Release/Source/eg/Calculator.java</a> -- the HP35 calculator and its fixture
<p></UL>
<hr>
<p>I'd like to see a manual interface to this calculator. It would provide keys and a display of the x value, just like a regular calculator. Doing this would point out some interesting differences between the programming and manual interfaces. One issue i'm curious about would be that keys would be digits, not complete numbers. So some mechanism would need to be created to convert. A manual interface would help to illustrate the concept of how you can test by going under the GUI. This is a hard concept for testers to understand.
<p>I have some comments on the perl hp35 simulator. I'm realizing that they'd be easier to make if i could cite tests. But that is hard, because they are random. Thus my first suggestion: Random tests should log the seed they used to generate them. And the script should be able to take a seed as an argument to regenerate the same test. This is a general rule for random tests, that i didn't get around to including in LessonsLearned. And, this would allow me to create a URL to a specific instance of a randomly generated test -- which would help me make my next suggestion.
<p>Second suggestion. Many of the tests using the hp35 simulator fail because of differences in precision. I would think that you'd want your fixture to be able to accept differences beyond a certain precision. Perhaps by setting a tolerance or something. Any tester who reported a bug simply because the implementation was calculating to a different level of precision than the oracle would be dismissed as wasting people's time. The fixtures need to have more sensitivity here. -- Oh i see i see that you (claim to) have addressed this in ScientificPrecision. Then why am i still seeing these problems?
<p>Hey. I'm seeing something strange with the calculator model. I generate a test (more) and then run it (run). And the test that is run is NOT THE SAME as the test that i just generated. This might be easier to track down if i could specify seeds.
<p>-- BretPettichord
<p><p><p>
</wiki>

<hr>
	Last edited November 23, 2002
</body>
</html>


